package com.xcf.controller.business.settlement;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xcf.controller.base.BaseController;
import com.xcf.service.business.settlement.AccountAdjustmentService;
import com.xcf.util.PageData;
import com.xcf.util.ResponseResult;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.net.URLDecoder;
import java.text.NumberFormat;
import java.util.List;
@Controller
@RequestMapping(value = "/account")
public class AccountAdjustmentController extends BaseController {
	String menuUrl = "account/adjustment";// 菜单地址(权限用)
	@Resource
	private AccountAdjustmentService accountAdjustmentService;
	/**
	 * 页面跳转
	 */
	@RequestMapping(value="/adjustment")
	public ModelAndView account(){
		ModelAndView mv = new ModelAndView();
		mv.setViewName("/business/accountadjustment/account_adjustment_list");
		return mv;
	}
//	/**
//	 * 收款对账数据查询
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/accountData")
//	public void accountData(HttpServletResponse response)throws Exception{
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		List<PageData>account = accountAdjustmentService.findCheckIncomeInfo(pd);  
//		JSONArray json = new JSONArray();
//		for(PageData p : account){
//			 JSONObject jo = new JSONObject();
//			 jo.put("id", p.get("id"));
//			 jo.put("check_code", p.getString("check_code"));
//			 jo.put("check_dept_name", p.getString("check_dept_name"));
//			 jo.put("checker_name", p.getString("checker_name"));
//			 if(p.get("check_date")!=null || p.get("check_date")!=""){
//				 	
//			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//			        String check_date = sdf.format(p.get("check_date"));
//				 jo.put("check_date", check_date);
//			 }
////			 jo.put("RECEIVABLES_TIME", p.get("RECEIVABLES_TIME"));
//			 jo.put("check_amount", p.get("check_amount"));
//			 jo.put("is_account_adjustment", p.get("is_account_adjustment"));
//			 jo.put("account_adjustment_person", p.getString("account_adjustment_person"));
//			 if(p.get("account_adjustment_date")!=null && p.get("account_adjustment_date")!=""){
//				 	
//			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//			        String account_adjustment_date = sdf.format(p.get("account_adjustment_date"));
//				 jo.put("account_adjustment_date", account_adjustment_date);
//			 }
//	            json.add(jo);
//		}
//		response.setContentType("text/html; charset=utf-8");
//		response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root1"+"\""+":"+json.toString()+"}");				
//		response.getWriter().flush();
//	}
//	/**
//	 * 成本对账数据查询
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/checkCostData")
//	public void checkCostData(HttpServletResponse response)throws Exception{
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		List<PageData>account = accountAdjustmentService.findCheckCost(pd);  
//		JSONArray json = new JSONArray();
//		for(PageData p : account){
//			 JSONObject jo = new JSONObject();
//			 jo.put("id", p.get("id"));
//			 jo.put("check_code", p.getString("check_code"));
//			 jo.put("check_dept_name", p.getString("check_dept_name"));
//			 jo.put("checker_name", p.getString("checker_name"));
//			 if(p.get("check_date")!=null || p.get("check_date")!=""){
//				 	
//			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//			        String check_date = sdf.format(p.get("check_date"));
//				 jo.put("check_date", check_date);
//			 }
////			 jo.put("RECEIVABLES_TIME", p.get("RECEIVABLES_TIME"));
//			 jo.put("check_amount", p.get("check_amount"));
//			 jo.put("is_account_adjustment", p.get("is_account_adjustment"));
//			 jo.put("account_adjustment_person", p.getString("account_adjustment_person"));
//			 if(p.get("account_adjustment_date")!=null && p.get("account_adjustment_date")!=""){
//				 	
//			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//			        String account_adjustment_date = sdf.format(p.get("account_adjustment_date"));
//				 jo.put("account_adjustment_date", account_adjustment_date);
//			 }
//	            json.add(jo);
//		}
//		response.setContentType("text/html; charset=utf-8");
//		response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root2"+"\""+":"+json.toString()+"}");				
//		response.getWriter().flush();
//	}
//	/**
//	 * 收款对账明细数据查询
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/checkIncomeDetailData")
//	public void checkIncomeDetailData(HttpServletResponse response)throws Exception{
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		List<PageData>account = accountAdjustmentService.findCheckIncomeDetail(pd);  
//		JSONArray json = new JSONArray();
//		for(PageData p : account){
//			 JSONObject jo = new JSONObject();
//			 jo.put("id",  p.get("id"));
//			 jo.put("item_id", p.get("item_id"));
//			 jo.put("check_code", p.get("check_code"));
//			 jo.put("check_code", p.get("check_code"));
//			 jo.put("BILL_CODE", p.getString("BILL_CODE"));
//			 jo.put("LADING_BILL_CODE", p.getString("LADING_BILL_CODE"));
//			 jo.put("TRADE_TYPE", p.getString("TRADE_TYPE"));
//			 jo.put("BOAT_ETD", p.get("BOAT_ETD"));
//			 jo.put("SETTLEMENT_UNIT", p.getString("SETTLEMENT_UNIT"));
//			 jo.put("COST_NAME", p.getString("COST_NAME"));
//			 jo.put("CONTAINER_TYPE", p.getString("CONTAINER_TYPE"));
//			 jo.put("CONTAINER_OWNER", p.getString("CONTAINER_OWNER"));
//			 jo.put("UNIT_PRICE", p.get("UNIT_PRICE"));
//			 jo.put("CONTAINER_NUM", p.get("CONTAINER_NUM"));
//			 jo.put("TOTALAMOUNT", p.get("TOTALAMOUNT"));
//			 jo.put("CURRENCY", p.getString("CURRENCY"));
//			 jo.put("EXCHANGE_RATE", p.get("EXCHANGE_RATE"));
//			 jo.put("BOAT_NAME", p.getString("BOAT_NAME"));
//			 jo.put("BOAT_VOYAGE_NAME", p.getString("BOAT_VOYAGE_NAME"));
//			 jo.put("SHIP_NAME", p.getString("SHIP_NAME"));
//			 jo.put("SHIP_VOYAGE_NAME", p.getString("SHIP_VOYAGE_NAME"));
//			 jo.put("SALER_NAME", p.getString("SALER_NAME"));
//			 jo.put("REMARK", p.getString("REMARK"));
//	            json.add(jo);
//		}
//		response.setContentType("text/html; charset=utf-8");
//		response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root3"+"\""+":"+json.toString()+"}");				
//		response.getWriter().flush();
//	}
//	/**
//	 * 成本对账明细数据查询
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/checkCostDetailData")
//	public void checkCostDetailData(HttpServletResponse response)throws Exception{
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		List<PageData>account = accountAdjustmentService.findCheckCostDetail(pd);  
//		JSONArray json = new JSONArray();
//		for(PageData p : account){
//			 JSONObject jo = new JSONObject();
//			 jo.put("id",  p.get("id"));
//			 jo.put("item_id", p.get("item_id"));
//			 jo.put("check_code", p.get("check_code"));
//			 jo.put("check_code", p.get("check_code"));
//			 jo.put("LADING_BILL_CODE", p.getString("LADING_BILL_CODE"));
//			 jo.put("BILL_TYPE", p.getString("BILL_TYPE"));
////			 if(p.get("check_date")!=null || p.get("check_date")!=""){
////				 	
////			        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
////			        String check_date = sdf.format(p.get("check_date"));
////				 jo.put("check_date", check_date);
////			 }
////			 jo.put("RECEIVABLES_TIME", p.get("RECEIVABLES_TIME"));
//			 jo.put("DINGCANG", p.get("DINGCANG"));
//			 jo.put("SETTLEMENT_UNIT", p.getString("SETTLEMENT_UNIT"));
//			 jo.put("COST_NAME", p.getString("COST_NAME"));
//			 jo.put("checker_name", p.getString("checker_name"));
//			 jo.put("check_date", p.get("check_date"));
//			 jo.put("CONTAINER_TYPE", p.getString("CONTAINER_TYPE"));
//			 jo.put("UNIT_PRICE", p.get("UNIT_PRICE"));
//			 jo.put("CONTAINER_NUM", p.get("CONTAINER_NUM"));
//			 jo.put("FEW", p.getString("FEW"));
//			 jo.put("TOTALAMOUNT", p.get("TOTALAMOUNT"));
//			 jo.put("corn_unit", p.getString("corn_unit"));
//			 jo.put("EXCHANGE_RATE", p.get("EXCHANGE_RATE"));
//			 jo.put("SHIP_NAME", p.getString("SHIP_NAME"));
//			 jo.put("SHIP_VOYAGE_NAME", p.getString("SHIP_VOYAGE_NAME"));
//			 jo.put("SHIP_ATD", p.get("SHIP_ATD"));
//			 jo.put("BOAT_NAME", p.getString("BOAT_NAME"));
//			 jo.put("BOAT_VOYAGE_NAME", p.getString("BOAT_VOYAGE_NAME"));
//			 jo.put("BOAT_ATD", p.get("BOAT_ATD"));
//			 jo.put("KEFU", p.getString("KEFU"));
//			 jo.put("SALER_NAME", p.getString("SALER_NAME"));
//			 jo.put("REMARK", p.getString("REMARK"));
//	            json.add(jo);
//		}
//		response.setContentType("text/html; charset=utf-8");
//		response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root4"+"\""+":"+json.toString()+"}");				
//		response.getWriter().flush();
//	}
//	/**
//	 * 收款调账后往费用表里面新增一条数据
//	 * @return
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/saveFeeInfo")
//	@ResponseBody
//	public String saveFeeInfo()throws Exception{
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		if(!pd.getString("item_id").isEmpty()&&!pd.getString("UNIT_PRICE").isEmpty()){
//			PageData pdq = accountAdjustmentService.findFee(pd);
//			pdq.put("UNIT_PRICE", pd.getString("UNIT_PRICE"));
//			//返回数量为Id，实际ID从传入参数里取
//			int Id = accountAdjustmentService.saveFeeInfo(pdq);
//			PageData pd2 = accountAdjustmentService.findCheckIncomeDetailInfo(pd);
//			pd2.put("item_id", pdq.get("ID"));
//			accountAdjustmentService.saveCheckIncomeDetailInfo(pd2);
//		}
//		return null;
//		
//	}
//	/**
//	 * 成本调账后往费用表里面新增一条数据
//	 * @return
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/saveFeeAndCostInfo")
//	@ResponseBody
//	public String saveFeeAndCostInfo()throws Exception{
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		if(!pd.getString("item_id").isEmpty()&&!pd.getString("UNIT_PRICE").isEmpty()){
//			PageData pdq = accountAdjustmentService.findFee(pd);
//			pdq.put("UNIT_PRICE", pd.getString("UNIT_PRICE"));
//			//返回数量为Id，实际ID从传入参数里取
//			int Id = accountAdjustmentService.saveFeeInfo(pdq);
//			PageData pd2 = accountAdjustmentService.findCheckCostDetailInfo(pd);
//			pd2.put("item_id", pdq.get("ID"));
//			accountAdjustmentService.saveCheckCostDetailInfo(pd2);
//		}
//		return null;
//		
//	}
//	/**
//	 * 调账申请
//	 * @return
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/updateInfo")
//	@ResponseBody
//	public String updateInfo()throws Exception{
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		accountAdjustmentService.updateCheckIncomeInfo(pd);
//		return null;
//		
//	}
//	/**
//	 * 调账申请
//	 * @return
//	 * @throws Exception
//	 */
//	@RequestMapping(value="/updateCostInfo")
//	@ResponseBody
//	public String updateCostInfo()throws Exception{
//		PageData pd = new PageData();
//		pd = this.getPageData();
//		accountAdjustmentService.updateCheckCost(pd);
//		return null;
//		
//	}
	/**
	 * 列表查询
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping(value="/findInfo")
	@ResponseBody
	public ResponseResult<Object> findInfo(int page ,int limit)throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		PageHelper.startPage(page, limit);	
		List<PageData>list = null;
		if(!pd.getString("state").isEmpty()){
		if(pd.getString("state").equals("1")){
			//收款
			list = accountAdjustmentService.findShou(pd);
		}else{
			//付款
			list = accountAdjustmentService.findFu(pd);
		}
		}else{
			//全部展示
			list = accountAdjustmentService.findListInfo(pd); 
		}
		return ResponseResult.success(new PageInfo(list));
	/*	 
		JSONArray json = new JSONArray();
		for(PageData p : account){
			 JSONObject jo = new JSONObject();
			 jo.put("ID",  p.get("ID"));
			 jo.put("BILL_CODE", p.getString("BILL_CODE"));
			 jo.put("LADING_BILL_CODE", p.getString("LADING_BILL_CODE"));
			 jo.put("BILL_TYPE", p.getString("BILL_TYPE"));
			 jo.put("DINGCANG", p.get("DINGCANG"));
			 jo.put("SETTLEMENT_UNIT", p.getString("SETTLEMENT_UNIT"));
			 jo.put("COST_NAME", p.getString("COST_NAME"));
			 jo.put("CONTAINER_TYPE", p.getString("CONTAINER_TYPE"));
			 jo.put("TAX_PRICE", p.get("TAX_PRICE"));
			 jo.put("NON_TAX_PRICE", p.get("NON_TAX_PRICE"));
			 jo.put("TAX_RATE", p.get("TAX_RATE"));
			 jo.put("CONTAINER_NUM", p.get("CONTAINER_NUM"));
			 jo.put("FEW", p.getString("FEW"));
			 jo.put("TOTALAMOUNT", p.get("TOTALAMOUNT"));
			 jo.put("CURRENCY", p.getString("CURRENCY"));
			 jo.put("EXCHANGE_RATE", p.get("EXCHANGE_RATE"));
			 jo.put("SHIP_NAME", p.getString("SHIP_NAME"));
			 jo.put("SHIP_VOYAGE_NAME", p.getString("SHIP_VOYAGE_NAME"));
			 jo.put("SHIP_ATD", p.get("SHIP_ATD"));
			 jo.put("BOAT_NAME", p.getString("BOAT_NAME"));
			 jo.put("BOAT_VOYAGE_NAME", p.getString("BOAT_VOYAGE_NAME"));
			 jo.put("BOAT_ATD", p.get("BOAT_ATD"));
			 jo.put("KEFU", p.getString("KEFU"));
			 jo.put("SALER_NAME", p.getString("SALER_NAME"));
			 jo.put("REMARK", p.getString("REMARK"));
	            json.add(jo);
		}
		response.setContentType("text/html; charset=utf-8");
		response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root3"+"\""+":"+json.toString()+"}");				
		response.getWriter().flush();*/
	}
	/**
	 * 查找费用信息
	 * @throws Exception
	 */
	@RequestMapping(value="/findFeeNameInfo")
	public void findFeeNameInfo(HttpServletResponse response)throws Exception{
		PageData pd = new PageData();
		pd = this.getPageData();
		String costName= URLDecoder.decode(pd.getString("COST_NAME"), "utf-8");
		//判断业务编号是否为空
		if(!pd.getString("BILL_CODE").isEmpty()){
			pd = accountAdjustmentService.findBookNoteByBillCode(pd);
			//判断业务类型是否为空
			if(!pd.getString("BUSINESS_TYPE_ID").isEmpty()){
				//通过业务类型判断内贸还是外贸查找不同表取出金额(业务类型ID是1或者2就是外贸，其余内贸)
				String fee = null;
				if(pd.get("BUSINESS_TYPE_ID").equals("1") || pd.get("BUSINESS_TYPE_ID").equals("2")){
					
					PageData cca =  accountAdjustmentService.findCCACostInfo(costName);
					PageData fix = accountAdjustmentService.findFixedFee(costName);
					if(!cca.isEmpty()){
						fee = cca.get("UNIT_PRICE").toString();
					}else if(!fix.isEmpty()){
						fee = fix.get("FEE_PRICE").toString();
					}else{  
						fee = "";
					}
				}else{
					PageData trade = accountAdjustmentService.findTradFee(costName);
					fee = trade.get("UNIT_PRICE").toString();
					
				}
				JSONObject jo = new JSONObject();
				JSONArray json = new JSONArray();
				jo.put("Fee", fee);
				json.add(jo);
				response.setContentType("text/html; charset=utf-8");
				response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root1"+"\""+":"+json.toString()+"}");				
				response.getWriter().flush();
				
			}
		}
	}
	/**
	 * 查找费用名称
	 * @throws Exception
	 */
	@RequestMapping(value="/findFeeProject")
	public void findFeeProject(HttpServletResponse response)throws Exception{
		PageData pd = new PageData();
		pd=this.getPageData();
		String COST_NAME= URLDecoder.decode(pd.getString("COST_NAME"), "utf-8");
		pd.put("COST_NAME", COST_NAME);
		if(!pd.getString("COST_NAME").isEmpty()){
			List<PageData> pdq = accountAdjustmentService.findFeeProject(pd);
			JSONArray json = new JSONArray();
			for(PageData p : pdq){
				JSONObject jo = new JSONObject();
				NumberFormat num = NumberFormat.getPercentInstance(); 
				num.setMaximumIntegerDigits(3); 
				num.setMaximumFractionDigits(2); 
				 double douNumber1=Double.parseDouble(p.get("TAX_RATE").toString());
				String TAX_RATE = num.format(douNumber1);
				jo.put("COST_NAME", p.getString("COST_NAME")+TAX_RATE);
				
				jo.put("TAX_RATE", p.get("TAX_RATE"));
				jo.put("COST_ITEM", p.get("COST_ITEM"));
				json.add(jo);
			}
			
			
			
			
			response.setContentType("text/html; charset=utf-8");
			response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root2"+"\""+":"+json.toString()+"}");				
			response.getWriter().flush();
		}
	}
	/**
	 * 保存信息
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/saveInfo")
	@ResponseBody
	public String saveInfo()throws Exception{
		PageData pd = new PageData();
		pd=this.getPageData();
		String COST_NAME= URLDecoder.decode(pd.getString("COST_NAME"), "utf-8");
		pd.put("COST_NAME", COST_NAME);
		int CONTAINER_NUM= Integer.parseInt(pd.getString("CONTAINER_NUM"));
		pd.put("CONTAINER_NUM", CONTAINER_NUM);
		pd.put("COST_ID", pd.getString("ID"));
		if(!pd.getString("TAX_RATE").isEmpty()){
			
			
			float TAX_RATE = Float.parseFloat(pd.getString("TAX_RATE"));
			pd.put("TAX_RATE", TAX_RATE);
		}
		if(!pd.getString("ADJUST_TAX_RATE").isEmpty()){
			String cc = pd.getString("ADJUST_TAX_RATE");
			NumberFormat nf=NumberFormat.getPercentInstance();
			Number m=nf.parse(cc);
			
			float ADJUST_TAX_RATE = Float.parseFloat(m.toString());
			pd.put("ADJUST_TAX_RATE", ADJUST_TAX_RATE);
		}
		if(!pd.getString("TAX_PRICE").isEmpty()){
			float TAX_PRICE = Float.parseFloat(pd.getString("TAX_PRICE"));
			pd.put("TAX_PRICE", TAX_PRICE);
		}
		if(!pd.getString("ADJUST_TAX_PRICE").isEmpty()){
			float ADJUST_TAX_PRICE = Float.parseFloat(pd.getString("ADJUST_TAX_PRICE"));
			pd.put("ADJUST_TAX_PRICE", ADJUST_TAX_PRICE);
		}
		if(!pd.getString("NON_TAX_PRICE").isEmpty()){
			float NON_TAX_PRICE = Float.parseFloat(pd.getString("NON_TAX_PRICE"));
			pd.put("NON_TAX_PRICE", NON_TAX_PRICE);
		}
		
		if(!pd.getString("ADJUST_NON_TAX_PRICE").isEmpty()){
			float ADJUST_NON_TAX_PRICE = Float.parseFloat(pd.getString("ADJUST_NON_TAX_PRICE"));
			pd.put("ADJUST_NON_TAX_PRICE", ADJUST_NON_TAX_PRICE);
		}
		if(!pd.getString("COST_ITEM").isEmpty()){
			String COST_ITEM= URLDecoder.decode(pd.getString("COST_NAME"), "utf-8");
			pd.put("COST_ITEM", COST_ITEM);
		}
		if(!pd.getString("SETTLEMENT_UNIT").isEmpty()){
			String SETTLEMENT_UNIT= URLDecoder.decode(pd.getString("SETTLEMENT_UNIT"), "utf-8");
			pd.put("SETTLEMENT_UNIT", SETTLEMENT_UNIT);
		}
		if(!pd.getString("CONTAINER_TYPE").isEmpty()){
			String SETTLEMENT_UNIT= URLDecoder.decode(pd.getString("CONTAINER_TYPE"), "utf-8");
			pd.put("CONTAINER_TYPE", SETTLEMENT_UNIT);
		}
		if(!pd.getString("COST_PLATE").isEmpty()){
			if(pd.getString("COST_PLATE").equals("undefined")){
				pd.put("COST_PLATE", "");
			}
		}
		pd.put("STATE", "0");
		accountAdjustmentService.saveInfo(pd);
		return null;
		
	}
	/**
	 * 查找调账商务审核
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/findSettlementInfo")
	public ModelAndView findSettlementInfo()throws Exception{
		ModelAndView view = new ModelAndView();
		view.setViewName("/business/accountadjustment/settlement_list");
		return view;
		
	}
	/**
	 * 数据查询
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping(value="/settlementInfo")
	@ResponseBody
	public ResponseResult<Object> settlementInfo(int page, int limit)throws Exception{
		PageData pd = new PageData();
		pd=this.getPageData();
		PageHelper.startPage(page, limit);
			List<PageData> list = accountAdjustmentService.findSettlementInfo(pd);
				
			return ResponseResult.success(new PageInfo(list));
			/*JSONArray json = new JSONArray();
			for(PageData p : pdq){
				JSONObject jo = new JSONObject();
				jo.put("ID", p.get("ID"));
				jo.put("COST_ID", p.getString("COST_ID"));
				jo.put("COST_PLATE", p.getString("COST_PLATE"));
				jo.put("BILL_CODE", p.get("BILL_CODE"));
				jo.put("LADING_BILL_CODE", p.get("LADING_BILL_CODE"));
				jo.put("SETTLEMENT_UNIT", p.get("SETTLEMENT_UNIT"));
				jo.put("COST_NAME", p.get("COST_NAME"));
				jo.put("CONTAINER_TYPE", p.get("CONTAINER_TYPE"));
				jo.put("TAX_PRICE", p.get("TAX_PRICE"));
				jo.put("ADJUST_TAX_PRICE", p.get("ADJUST_TAX_PRICE"));
				jo.put("NON_TAX_PRICE", p.get("NON_TAX_PRICE"));
				jo.put("ADJUST_NON_TAX_PRICE", p.get("ADJUST_NON_TAX_PRICE"));
				jo.put("TAX_RATE", p.get("TAX_RATE"));
				jo.put("ADJUST_TAX_RATE", p.get("ADJUST_TAX_RATE"));
				jo.put("CONTAINER_NUM", p.get("CONTAINER_NUM"));
				jo.put("ADJUST_TAX_RATE", p.get("ADJUST_TAX_RATE"));
				jo.put("TOTALAMOUNT", p.get("TOTALAMOUNT"));
				jo.put("CURRENCY", p.get("CURRENCY"));
				json.add(jo);
			}
			
			
			
			
			response.setContentType("text/html; charset=utf-8");
			response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root"+"\""+":"+json.toString()+"}");				
			response.getWriter().flush();
*/
	}
	/**
	 * 审批通过，更新至费用表
	 * @throws Exception
	 */
	@RequestMapping(value="/saveFeeInfo")
	@ResponseBody
	public String saveFeeInfo()throws Exception{
		PageData pd = new PageData();
		pd=this.getPageData();

		String data = pd.getString("array");

		JSONArray items = JSONArray.fromObject(data);
		for(int i=0,size=items.size();i<size;i++){
			JSONObject item = items.getJSONObject(i);
			String id = item.getString("COST_ID").trim();
			PageData pdq = new PageData();
			pdq.put("COST_ID", id);
			pdq.put("ADJUST_TAX_RATE", item.get("ADJUST_TAX_RATE"));
			pdq.put("ADJUST_TAX_PRICE", item.get("ADJUST_TAX_PRICE"));
			pdq.put("ADJUST_NON_TAX_PRICE", item.get("ADJUST_NON_TAX_PRICE"));
			pdq.put("BILL_CODE", item.get("BILL_CODE"));
			pdq.put("LADING_BILL_CODE", item.get("LADING_BILL_CODE"));
			pdq.put("COST_NAME", item.get("COST_NAME"));
			accountAdjustmentService.updateSettlementInfo(pdq);
			accountAdjustmentService.updateCopeCost(pdq);
			String id1 = item.getString("ID").trim();
			PageData pdqw = new PageData();
			pdqw.put("ID", id1);
			pdqw.put("STATE", "1");
			accountAdjustmentService.editState(pdqw);
		}
		
		return null;
	}
	/**
	 * 审核不通过，更新至退回表
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/NoPass")
	public String NoPass()throws Exception{
		PageData pd = new PageData();
		pd=this.getPageData();
		String data = pd.getString("array");

		JSONArray items = JSONArray.fromObject(data);
		for(int i=0,size=items.size();i<size;i++){
			
			JSONObject item = items.getJSONObject(i);
			String id = item.getString("ID").trim();
			PageData pdq = new PageData();
			pdq.put("ID", id);
			pdq.put("COST_ID", item.get("COST_ID"));
			pdq.put("ADJUST_TAX_RATE", item.get("ADJUST_TAX_RATE"));
			pdq.put("ADJUST_TAX_PRICE", item.get("ADJUST_TAX_PRICE"));
			pdq.put("ADJUST_NON_TAX_PRICE", item.get("ADJUST_NON_TAX_PRICE"));
			pdq.put("BILL_CODE", item.get("BILL_CODE"));
			pdq.put("LADING_BILL_CODE", item.get("LADING_BILL_CODE"));
			pdq.put("COST_NAME", item.get("COST_NAME"));
			pdq.put("SETTLEMENT_UNIT", item.get("SETTLEMENT_UNIT"));
			pdq.put("CONTAINER_TYPE", item.get("CONTAINER_TYPE"));
			pdq.put("TAX_PRICE", item.get("TAX_PRICE"));
			pdq.put("NON_TAX_PRICE", item.get("NON_TAX_PRICE"));
			pdq.put("TAX_RATE", item.get("TAX_RATE"));
			pdq.put("CONTAINER_NUM", item.get("CONTAINER_NUM"));
			
			pdq.put("COST_PLATE", item.get("COST_PLATE"));
			pdq.put("COST_ITEM", item.get("COST_ITEM"));
			pdq.put("CURRENCY", item.get("CURRENCY"));
			pdq.put("REC_ID", id);
			pdq.put("STATE", "0");
			
			accountAdjustmentService.saveNoPass(pdq);
			PageData pdqw = new PageData();
			pdqw.put("ID", id);
			pdqw.put("STATE", "2");
			accountAdjustmentService.editState(pdqw);
		}
		
		return null;
	}
	/**
	 * 跳转退后页面
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value = "/findReturnInfo")
	public ModelAndView findReturnInfo()throws Exception{
		ModelAndView view = new ModelAndView();
		view.setViewName("/business/accountadjustment/return_list");
		return view;
		
	}
	/**
	 * 查找退回信息
	 * @param response
	 * @return 
	 * @throws Exception
	 */
	@RequestMapping(value="/findNopassReturnInfo")
	@ResponseBody
	public ResponseResult<Object> findNopassReturnInfo(int page, int limit)throws Exception{
		PageData pd = new PageData();
		pd=this.getPageData();
		PageHelper.startPage(page, limit);
			List<PageData> list = accountAdjustmentService.findReturnInfo(pd);
			return ResponseResult.success(new PageInfo(list));
			/*JSONArray json = new JSONArray();
			for(PageData p : pdq){
				JSONObject jo = new JSONObject();
				jo.put("ID", p.get("ID"));
				jo.put("COST_PLATE", p.getString("COST_PLATE"));
				jo.put("BILL_CODE", p.get("BILL_CODE"));
				jo.put("LADING_BILL_CODE", p.get("LADING_BILL_CODE"));
				jo.put("SETTLEMENT_UNIT", p.get("SETTLEMENT_UNIT"));
				jo.put("COST_NAME", p.get("COST_NAME"));
				jo.put("CONTAINER_TYPE", p.get("CONTAINER_TYPE"));
				jo.put("TAX_PRICE", p.get("TAX_PRICE"));
				jo.put("ADJUST_TAX_PRICE", p.get("ADJUST_TAX_PRICE"));
				jo.put("NON_TAX_PRICE", p.get("NON_TAX_PRICE"));
				jo.put("ADJUST_NON_TAX_PRICE", p.get("ADJUST_NON_TAX_PRICE"));
				jo.put("TAX_RATE", p.get("TAX_RATE"));
				jo.put("ADJUST_TAX_RATE", p.get("ADJUST_TAX_RATE"));
				jo.put("CONTAINER_NUM", p.get("CONTAINER_NUM"));
				jo.put("ADJUST_TAX_RATE", p.get("ADJUST_TAX_RATE"));
				jo.put("TOTALAMOUNT", p.get("TOTALAMOUNT"));
				jo.put("CURRENCY", p.get("CURRENCY"));
				json.add(jo);
			}
			response.setContentType("text/html; charset=utf-8");
			response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"5"+"\""+","+"\""+"root"+"\""+":"+json.toString()+"}");				
			response.getWriter().flush();*/
	}
	/**
	 * 删除退回表信息（实际上是修改，让数据不出现在列表）
	 * @throws Exception
	 */
	@RequestMapping(value="/deleteInfo")
	public String deleteInfo()throws Exception{
		PageData pd= new PageData();
		pd=this.getPageData();
		String data = pd.getString("array");

		JSONArray items = JSONArray.fromObject(data);
		for(int i=0,size=items.size();i<size;i++){
			
			JSONObject item = items.getJSONObject(i);
//			String REC_ID = item.getString("REC_ID").trim();
			
//			PageData pdq = new PageData();
//			pdq.put("ID", REC_ID);
//			pdq.put("STATE", "0");
//			accountAdjustmentService.editState(pdq);
			String id = item.getString("ID").trim();
			PageData pdqw = new PageData();
			pdqw.put("ID", id);
			pdqw.put("STATE", "1");
			accountAdjustmentService.deleteInfo(pdqw);
		}
		return null;
		
	}
}
